package com.wzxy.pf.budget.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wzxy.pf.budget.entity.Budget;
import com.wzxy.pf.budget.service.BudgetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhl
 * @since 2023-04-01
 */
@RestController
@RequestMapping("/budget")
public class BudgetController {
    @Autowired
    private BudgetService budgetService;
    /*
    进到budget页面，加载显示数据
     */
    @GetMapping("/home/{pageSize}/{uId}")
    public IPage<Budget> findByuId(@PathVariable("pageSize") Integer pageSize, @PathVariable("uId") Integer uId){
        return  budgetService.findByuId(1,pageSize,uId);

    }
    /*
    翻页功能
     */
@PostMapping("/page/{cruPage}/{pageSize}/{uId}")
    public IPage<Budget> page(@PathVariable("cruPage") Integer cruPage,@PathVariable("pageSize") Integer pageSize,@PathVariable("uId") Integer uId ){
    return   budgetService.findByuId(cruPage,pageSize,uId);
    }

    /*
    逻辑删除
     */
    @PostMapping("/delete")
    public int a(@RequestBody List<String> ids) {
        System.out.println(ids);
   return budgetService.delete(ids);
    }
    /*
    添加预算
 */
    @PostMapping("/save")
    public int saveBudget(@RequestBody Budget budget){
        System.out.println(budget);
       return budgetService.saveBudget(budget);

    }
    /*
    更新数据
*/
    @PostMapping("/update")
    public int updateBudget(@RequestBody Budget budget){
        return budgetService.updateBudget(budget);
    }
    /*
    月份查询
     */
    @GetMapping("/search/{time}")
    public  List<Budget> search(@PathVariable("time") String time){
return budgetService.search(time);

    }
}

